# 里面存放一些基础设置，包括连接数据库，选择开发环境，qq邮箱的设定，超级管理员存放等

# 文件上传操作还要再看看。      文件.save(路径)

import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))      #因项目拆分导致rend_tamplate找不到模板路径的解决办法
TEMPLATE_FOLDER = os.path.join(BASE_DIR,'templates')                        #static 也是同理

# 电影图片路径
FILE_PATH_PREFIX = '/static/uploads/icons/'

UPLOADS_DIR = os.path.join(BASE_DIR , 'App/static/uploads/icons/')

# 支付宝接口配置
ALIPAY_APPID = "2016102500759292"

APP_PRIVATE_KEY = open(os.path.join(BASE_DIR, 'alipay_config/app_private_key.pem'), 'r').read() # 自己的私钥

ALIPAY_PUBLIC_KEY = open(os.path.join(BASE_DIR, 'alipay_config/alipay_public_key.pem'), 'r').read() # 注意是支付宝返回的公钥，不是自己的


def get_db_url(dbinfo):
    engine = dbinfo.get("ENGINE")
    driver = dbinfo.get("DRIVER")
    user = dbinfo.get("USER")
    password = dbinfo.get("PASSWORD")
    host = dbinfo.get("HOST")
    port = dbinfo.get("PORT")
    dbname = dbinfo.get("DBNAME")
    return "{}+{}://{}:{}@{}:{}/{}".format(engine , driver , user , password , host , port , dbname)


class Config:
    TESTING = False

    DEBUG = False

    JSON_AS_ASCII = False

    SQLALCHEMY_TRACK_MODIFICATIONS = False

    SECRET_KEY = 'Guoss12345'

# 开发、测试、演示、线上 这四个环境

class DevelopConfig(Config):

    ENV = "develop"

    DEBUG = True

    DEBUG_TB_PROFILER_ENABLED = True

    dbinfo = {
        "ENGINE":"mysql",
        "DRIVER":"pymysql",
        "USER":"root",
        "PASSWORD":"root",
        "HOST":"localhost",
        "PORT":"3306",
        "DBNAME":"FlaskTpp"
    }

    SQLALCHEMY_DATABASE_URI = get_db_url(dbinfo)

    MAIL_SERVER = "smtp.qq.com"
    MAIL_PORT = 25
    # MAIL_PORT = 465
    # MAIL_USE_SSL = True
    MAIL_USERNAME = "842854522@qq.com"
    MAIL_PASSWORD = "mlalaqnfnryybajf"      #我qq邮箱的第三方授权码
    MAIL_DEFAULT_SENDER = MAIL_USERNAME


class TestingConfig(Config):

    TESTING = True

    dbinfo = {
        "ENGINE":"mysql",
        "DRIVER":"pymysql",
        "USER":"root",
        "PASSWORD":"root",
        "HOST":"127.0.0.1",
        "PORT":"3306",
        "DBNAME":"*****"
    }

    SQLALCHEMY_DATABASE_URI = get_db_url(dbinfo)



class StagingConfig(Config):

    dbinfo = {
        "ENGINE":"mysql",
        "DRIVER":"pymysql",
        "USER":"root",
        "PASSWORD":"root",
        "HOST":"localhost",
        "PORT":"3306",
        "DBNAME":"*****"
    }

    SQLALCHEMY_DATABASE_URI = get_db_url(dbinfo)


class ProductConfig(Config):

    ENV = "production"

    dbinfo = {
        "ENGINE":"mysql",
        "DRIVER":"pymysql",
        "USER":"root",
        "PASSWORD":"root",
        "HOST":"localhost",
        "PORT":"3306",
        "DBNAME":"*****"
    }

    SQLALCHEMY_DATABASE_URI = get_db_url(dbinfo)


envs = {
    "develop":DevelopConfig,
    "testing":TestingConfig,
    "staging":StagingConfig,
    "product":ProductConfig,
    "default":DevelopConfig
}


# 超级管理员的username存放处
ADMINS = {
    'Guoss' ,
    'Rock'
}

